/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "user_char" )
@IdClass( UserCharPK.class )
@NamedQueries(
  {
    @NamedQuery( name = "UserChar.findByUserId",
                  query = "SELECT u FROM UserChar u WHERE u.userId = :userId" ),
    @NamedQuery( name = "UserChar.findByCharId",
                  query = "SELECT u FROM UserChar u WHERE u.charId = :charId" ),
    @NamedQuery( name = "UserChar.findByCharName",
                 query = "SELECT u FROM UserChar u WHERE u.charName = :charName" ) } )
public class UserChar implements Serializable {
  private int userId;
  private int charId;


  private String charName;
  private Collection<Guild> guildIdCollection;
  private Collection<MudPlace> placeIdCollection;
  private Collection<SkillGroupProf> skillGroupProfCollection;
  private CharRace raceId;
  private UserAccount userAccount;
  private Collection<UserCharItem> userCharItemCollection;
  private Collection<SkillProf> skillProfCollection;


  public UserChar() {
  }


  public UserChar(  int userId, int charId, String charName ) {
    this(userId,charId);
    this.charName = charName;
  }


  public UserChar( int userId, int charId ) {
    this.userId = userId;
    this.charId = charId;
  }


  @Id
  @GeneratedValue( strategy = GenerationType.SEQUENCE )
  @Column( name = "char_id", nullable = false )
  public int getCharId() {
    return charId;
  }


  public void setCharId( int charId ) {
    this.charId = charId;
  }


  @Id
  @Column( name = "user_id", nullable = false )
  public int getUserId() {
    return userId;
  }


  public void setUserId( int userId ) {
    this.userId = userId;
  }
  

  @Column( name = "char_name", nullable = false, length = 50, unique=true )
  public String getCharName() {
    return charName;
  }


  public void setCharName( String charName ) {
    this.charName = charName;
  }


  @ManyToMany( mappedBy = "userCharCollection" )
  public Collection<Guild> getGuildIdCollection() {
    return guildIdCollection;
  }


  public void setGuildIdCollection( Collection<Guild> guildIdCollection ) {
    this.guildIdCollection = guildIdCollection;
  }


  @ManyToMany( mappedBy = "userCharCollection" )
  public Collection<MudPlace> getPlaceIdCollection() {
    return placeIdCollection;
  }


  public void setPlaceIdCollection( Collection<MudPlace> placeIdCollection ) {
    this.placeIdCollection = placeIdCollection;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "userChar" )
  public Collection<SkillGroupProf> getSkillGroupProfCollection() {
    return skillGroupProfCollection;
  }


  public void setSkillGroupProfCollection( Collection<SkillGroupProf> skillGroupProfCollection ) {
    this.skillGroupProfCollection = skillGroupProfCollection;
  }


  @JoinColumn( name = "race_id", referencedColumnName = "race_id", nullable = false )
  @ManyToOne
  public CharRace getRaceId() {
    return raceId;
  }


  public void setRaceId( CharRace raceId ) {
    this.raceId = raceId;
  }


  @JoinColumn( name = "user_id", referencedColumnName = "user_id", insertable =
                                                                   false, updatable =
                                                                          false )
  @ManyToOne
  public UserAccount getUserAccount() {
    return userAccount;
  }


  public void setUserAccount( UserAccount userAccount ) {
    this.userAccount = userAccount;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "userChar" )
  public Collection<UserCharItem> getUserCharItemCollection() {
    return userCharItemCollection;
  }


  public void setUserCharItemCollection( Collection<UserCharItem> userCharItemCollection ) {
    this.userCharItemCollection = userCharItemCollection;
  }


  @OneToMany( cascade = CascadeType.ALL, mappedBy = "userChar" )
  public Collection<SkillProf> getSkillProfCollection() {
    return skillProfCollection;
  }


  public void setSkillProfCollection( Collection<SkillProf> skillProfCollection ) {
    this.skillProfCollection = skillProfCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) userId;
    hash += (int) charId;
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof UserChar ) ) {
      return false;
    }
    UserChar other = (UserChar) object;
    if ( this.userId != other.userId ) {
      return false;
    }
    if ( this.charId != other.charId ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.UserChar[userId=" + userId + ", charId=" + charId + "]";
  }

}
